package com.example.wechat2

import android.content.ContentValues
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


        btn_chat.setOnClickListener{


            replaceFragment(ChatFragment())
        }
        btn_puq.setOnClickListener{

            replaceFragment(PuqFragment())
        }
        btn_friends.setOnClickListener{

            replaceFragment(FriendsFragment())
        }
        btn_me.setOnClickListener{

            replaceFragment(MeFragment())
        }

    }



    override fun onStart(){
        super.onStart()
        println("onStart")
        Log.d(ContentValues.TAG,"onDestory")
    }
    override fun onPause(){
        super.onPause()

        println("onPause")
        Log.d(ContentValues.TAG,"onPause")
    }
    override fun onRestart(){
        super.onRestart()
        println("onRestart")
        Log.d(ContentValues.TAG,"onRestart")
    }
    override fun onResume(){
        super.onResume()
        println("onResume")
        Log.d(ContentValues.TAG,"onResume")
    }
    override fun onStop(){
        super.onStop()
        println("onStop")
        Log.d(ContentValues.TAG,"onStop")
    }
    override fun onDestroy(){
        super.onDestroy()
        println("onDestroy")
        Log.d(ContentValues.TAG,"onDestory")
    }


    private fun replaceFragment(fragment: Fragment) {

        val fragmentManager = supportFragmentManager
        val transaction = fragmentManager.beginTransaction()
        transaction.replace(R.id.framelayout_upContainer,fragment)
        transaction.commit()

    }

}